/* new-sprite-dialog.vala
 *
 * Copyright (C) 2010, 2011  Richard Talbot-Watkins
 * Copyright (C) 2010, 2011  Dave Jeffery
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Authors:
 *  Richard Talbot-Watkins <richtw1@gmail.com>
 * 	Dave Jeffery <david.richard.jeffery@gmail.com>
 */

using Gtk;

/**
 * New sprite dialog box for Beeb Spriter.
 *
 * @author Richard Talbot-Watkins <richtw1@gmail.com>
 * @author Dave Jeffery <david.richard.jeffery@gmail.com>
 * @version 2010.0114
 * @since 0.1
 */
public class BeebSpriter.NewSpriteDialog : Dialog {
	/**
	 * Text entry field for sprite name.
	 */
	public Entry name_entry;

	/**
	 * Spin button for sprite width.
	 */
	public SpinButton width_spinbutton;

	/**
	 * Spin button for sprite height.
	 */
	public SpinButton height_spinbutton;

	/**
	 * Minimum width for sprite - varies with BBC Micro screen mode.
	 */
	private float min_width;

	/**
	 * Maximum width for sprite - varies with BBC Micro screen mode.
	 */
	private float max_width;

	/**
	 * Constructor for the new sprite dialog box.
	 */
	public NewSpriteDialog (Window parent_window, float min_width, 
							float max_width) {
		this.min_width = min_width;
		this.max_width = max_width;

		title = _("New sprite");
		border_width = 5;
		set_default_size (160, 120);
		icon = parent_window.icon;
		resizable = false;
		set_transient_for (parent_window);

		create_widgets ();
	}

	/**
	 * Creates the widgets that appear on the new sprite dialog box.
	 */
	private void create_widgets () {
		/* Create boxes to pack widgets into. */
		var widget_hbox = new HBox (false, 8);
		var label_vbox = new VBox (false, 8);
		var field_vbox = new VBox (false, 8);

		/* Add labels */
		var name_label = new Label (_("Name:"));
		var width_label = new Label (_("Width:"));
		var height_label = new Label (_("Height:"));

		name_label.xalign = 0f;
		width_label.xalign = 0f;
		height_label.xalign = 0f;

		label_vbox.pack_start (name_label);
		label_vbox.pack_start (width_label);
		label_vbox.pack_start (height_label);

		/* Add entry fields */
		name_entry = new Entry ();
		name_entry.activates_default = true;

		width_spinbutton = new SpinButton.with_range (min_width, max_width, 1.0);
		height_spinbutton = new SpinButton.with_range (1.0, 256.0, 1.0);
		width_spinbutton.xalign = 1f;
		height_spinbutton.xalign = 1f;
		width_spinbutton.value = 8;
		height_spinbutton.value = 8;
		width_spinbutton.activates_default = true;
		height_spinbutton.activates_default = true;

		var width_units_label = new Label (_("pixels"));
		var height_units_label = new Label (_("pixels"));

		var entry_hbox = new HBox (false, 0);
		entry_hbox.pack_start (name_entry, false, false, 4);

		var width_hbox = new HBox (false, 0);
		width_hbox.pack_start (width_spinbutton, false, false, 4);
		width_hbox.pack_start (width_units_label, false, false, 4);

		var height_hbox = new HBox (false, 0);
		height_hbox.pack_start (height_spinbutton, false, false, 4);
		height_hbox.pack_start (height_units_label, false, false, 4);

		field_vbox.pack_start (entry_hbox);
		field_vbox.pack_start (width_hbox);
		field_vbox.pack_start (height_hbox);

		/* Add labels and entry fields to dialog */
		widget_hbox.pack_start (label_vbox);
		widget_hbox.pack_start (field_vbox);	
		vbox.pack_start (widget_hbox);
		vbox.show_all ();

		/* Add buttons. */
		add_button (STOCK_CANCEL, ResponseType.CANCEL);
		add_button (_("Create"), ResponseType.APPLY);
		set_default_response (ResponseType.APPLY);
	}
}
